package com.hx.er.common.interceptor;

import com.hx.er.bean.base.UserBean;
import com.hx.er.common.system.Constants;
import com.hx.er.common.system.ErLanguages;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LanguageInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 7928238152002519440L;

	@Override
	public String intercept(ActionInvocation ai) throws Exception {
		// 检查用户是否登录
		UserBean userInfo = (UserBean) ActionContext.getContext().getSession().get(Constants.SESSION_USER_INFO);
		if (userInfo != null) {
			// 设置语言
			ActionContext.getContext().setLocale(ErLanguages.getLocale(userInfo.getDefLangId()));
		}

		return ai.invoke();
	}
}
